package com.jason.basicandroid.ui.control;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.TimePicker;

public class DateTimeDemo extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    	DatePicker upDatePicker = (DatePicker)findViewById(R.id.upDatePicker);
    	DatePicker downDatePicker = (DatePicker)findViewById(R.id.downDatePicker);
    	
    	upDatePicker.init(2011, 5, 18, null);
    	downDatePicker.init(2011, 5, 19, null);

    	TimePicker upTimePicker = (TimePicker)findViewById(R.id.upTimePicker);
    	TimePicker downTimePicker = (TimePicker)findViewById(R.id.downTimePicker);

    	upTimePicker.setIs24HourView(true);
    	upTimePicker.setCurrentHour(10);
    	upTimePicker.setCurrentMinute(10); 
    	
    	downTimePicker.setIs24HourView(false);
    	downTimePicker.setCurrentHour(9);
    	downTimePicker.setCurrentMinute(9);

    	LinearLayout dateLayout = (LinearLayout)findViewById(R.id.dateLayout);
    	LinearLayout timeLayout = (LinearLayout)findViewById(R.id.timeLayout);
          
    	dateLayout.setVisibility(View.VISIBLE);
    	timeLayout.setVisibility(View.GONE);
    }

    public void onUpDateBtnClick(View srcBtn) {
    	DatePicker upDatePicker = (DatePicker)findViewById(R.id.upDatePicker);
    	DatePicker downDatePicker = (DatePicker)findViewById(R.id.downDatePicker);
    	
    	upDatePicker.updateDate(downDatePicker.getYear(),
    			downDatePicker.getMonth(), downDatePicker.getDayOfMonth());
    }

    public void onDownDateBtnClick(View srcBtn) {
    	DatePicker upDatePicker = (DatePicker)findViewById(R.id.upDatePicker);
    	DatePicker downDatePicker = (DatePicker)findViewById(R.id.downDatePicker);
    	
    	downDatePicker.updateDate(upDatePicker.getYear(),
    			upDatePicker.getMonth(), upDatePicker.getDayOfMonth());
    }

    public void onUpTimeBtnClick(View srcBtn) {
    	TimePicker upTimePicker = (TimePicker)findViewById(R.id.upTimePicker);
    	TimePicker downTimePicker = (TimePicker)findViewById(R.id.downTimePicker);
    	
    	upTimePicker.setIs24HourView(downTimePicker.is24HourView());
    	upTimePicker.setCurrentHour(downTimePicker.getCurrentHour());
    	upTimePicker.setCurrentMinute(downTimePicker.getCurrentMinute());
    }

    public void onDownTimeBtnClick(View srcBtn) {
    	TimePicker upTimePicker = (TimePicker)findViewById(R.id.upTimePicker);
    	TimePicker downTimePicker = (TimePicker)findViewById(R.id.downTimePicker);
    	
    	downTimePicker.setIs24HourView(upTimePicker.is24HourView());
    	downTimePicker.setCurrentHour(upTimePicker.getCurrentHour());
    	downTimePicker.setCurrentMinute(upTimePicker.getCurrentMinute());
    }

    public void onBtnDateClick(View srcBtn) {
    	LinearLayout dateLayout = (LinearLayout)findViewById(R.id.dateLayout);
    	LinearLayout timeLayout = (LinearLayout)findViewById(R.id.timeLayout);
          
    	dateLayout.setVisibility(View.VISIBLE);
    	timeLayout.setVisibility(View.GONE);
    }

    public void onBtnTimeClick(View srcBtn) {
    	LinearLayout dateLayout = (LinearLayout)findViewById(R.id.dateLayout);
    	LinearLayout timeLayout = (LinearLayout)findViewById(R.id.timeLayout);
          
    	dateLayout.setVisibility(View.GONE);
    	timeLayout.setVisibility(View.VISIBLE);
    }
}